import { Component, OnInit, EventEmitter, Output } from "@angular/core";
import {BizfileService} from '../../../../../@core/service/case-review/doc-service/api/bizfile.service'
import { ClueDataService } from "../../../../../@core/service/clue-service/clue-data.service";
import * as moment from 'moment';
@Component({
  selector: 'app-closing-approval',
  templateUrl: './closing-approval.component.html',
  styleUrls: ['./closing-approval.component.scss']
})
export class ClosingApprovalComponent implements OnInit {
  @Output('loadSpin') loadSpin = new EventEmitter();

  // 时间
  private date:any = new Date();
  //加载动画
  public loading:boolean = false;
  BizFile: any;


  public isReadonly:boolean = false;
  public doctype: string;     // 文书名称
  public condition: string;   // 新增or审批条件
    // 请求数据
    public filedata: any = {data: {stage: null}};
    public caseType: any;        // 案件环节
  //type选中值
  public treeValue: any;
  //区域数据
  public areaData: any;
  //省级联动
  public provinces: any[];
  //市级联动
  public cities: any[];
  //县级联动
  public counties: any[];
  //选择内容
  public addressDetails: any[] = [];
  public addressName: any[] = [];
  public sortValue: string = "0";
  public getSelectValue:string;

  // 案件承办人员日期
  private _caseDate:any = this.date;
  //docid 如果是修改会传入docid
  public docid:string;
  //form内容
  public formJson: any = {
    caseFiDate:moment(this.date).format('YYYY-MM-DD'),
    penDecDate:moment(this.date).format('YYYY-MM-DD'),
    eYear:this.date.getFullYear(),
    eMon : this.date.getMonth()+1,
    eDay : this.date.getDate(),
    exeperName:sessionStorage.getItem('realName')
  };
  public get caseDate(){
    return this._caseDate
  }
  public set caseDate(val){
    if(val){
      let date:Date = new Date(val);
      this.formJson.eYear = date.getFullYear();
      this.formJson.eMon = date.getMonth()+1;
      this.formJson.eDay = date.getDate();
    }
    this._caseDate=val;
}



  constructor(
    public bizService:BizfileService,
    public clueData: ClueDataService,
    ) {
      this.areaData = clueData.area;
     }

  ngOnInit() {
    if(this.docid){ 
      this.bizService.queryBizFileByDocid(this.docid).subscribe(({data}:any)=>{
        this.loadSpin.emit(false);
        if(data){
          if(data.stage) this.getSelectValue = data.stage;
          this.BizFile = data;
          this.formJson = JSON.parse(data.formJson);
          // 时间回显
          this.caseDate = this.formJson.eYear+'-'+this.formJson.eMon+'-'+this.formJson.eDay;
          if(this.formJson.caseType){
            this.treeValue = JSON.parse(this.formJson.caseType);
          }
          if(this.formJson.fontName||this.formJson.name||this.formJson.idNum){
            this.sortValue = '1';
          }
        }
      })
  }else{
      
  }
}

//处罚决定书
processingDecision(e,str){
  if(e){
    this.formJson[str]="☑"

  }else{
    this.formJson[str] = null;
    if(str == 'cO'){
      this.formJson.cOCon = null
    }
  }
  if(!this.formJson.cO){
    this.formJson.cOCon = null;
  }
}
// 行政处罚决定执行方式
implementationModalities(e,str){
  if(e){
    this.formJson[str]="☑"

  }else{
    this.formJson[str] = null;
    if(str == 'oExe'){
      this.formJson.oCon = null
    }
  }
  if(!this.formJson.oExe){
    this.formJson.oCon = null;
  }
}
    //tree选择
    treeOnChange(event) {
  
    }
  selectChange(event){
    this.getSelectValue = event;
  }
}
